﻿<%@ Page Language="C#" AutoEventWireup="true" Codebehind="studentslist.aspx.cs" Inherits="LabMS.Web.CommonPage.studentslist" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>学生查询列表</title>
    <base target="_self" />
    <link type="text/css" rel="stylesheet" href="../style/screen.css" />
    <link href="../css/jquery.wysiwyg.css" rel="stylesheet" type="text/css" />
    <!--[if lte IE 6]>
    <link type="text/css" rel="stylesheet" href="../../style/ie6.css" />
    <![endif]-->
    <!--[if lte IE 7]>
    <link type="text/css" rel="stylesheet" href="../../style/ie7.css" />
    <![endif]-->
</head>
<body class="mainBody">
    <form id="form1" runat="server">
        <div class="main">
            <p>
                年级
                <asp:DropDownList ID="ddlYear" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
                </asp:DropDownList>
                专业
                <asp:DropDownList ID="ddlPro" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
                </asp:DropDownList>
                班级
                <asp:DropDownList ID="ddlClass" runat="server">
                </asp:DropDownList>
                学号
                <asp:TextBox ID="tbSNub" runat="server"></asp:TextBox>
                姓名
                <asp:TextBox ID="tbSName" runat="server"></asp:TextBox>
                <asp:Button ID="btnSearch" CssClass="button" runat="server" Text="搜索" OnClick="btnSearch_Click" />
                <input id="btRest" type="button" class="button" value="重置" onclick="javascript:window.location.href='studentslist.aspx';" />
            </p>
            <p>
                <input id="btOK" class="button" disabled="disabled" type="button" value="确定" />
            </p>
        </div>
        <div class="main">
            <asp:GridView ID="gvStudents" runat="server" Width="100%" PageSize="10" AllowPaging="true"
                DataKeyNames="ID" AutoGenerateColumns="False" OnRowDataBound="gvStudents_RowDataBound"
                OnPageIndexChanging="gvStudents_PageIndexChanging" CssClass="infoTable">
                <Columns>
                    <asp:TemplateField ItemStyle-CssClass="checkBox">
                        <HeaderTemplate>
                            <asp:CheckBox ID="CBAll" runat="server" />
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:CheckBox runat="server" ID="checkdel" /></ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="ID" ShowHeader="false" HeaderStyle-CssClass="none" ItemStyle-CssClass="none" />
                    <asp:BoundField DataField="Student_Code" HeaderText="学号" />
                    <asp:BoundField DataField="Student_Name" HeaderText="姓名" />
                </Columns>
                <HeaderStyle CssClass="header" />
                <RowStyle HorizontalAlign="Center" />
                <EmptyDataTemplate>
                    <a style="color: Red">无数据</a>
                </EmptyDataTemplate>
            </asp:GridView>
            <asp:Label ID="lbboolSearch" runat="server" Visible="false" Text=""></asp:Label>
        </div>
    </form>

    <script type="text/javascript" src="../js/jQuery/jquery-1.3.1.js"></script>

    <script type="text/javascript" src="../js/site.js"></script>

    <script type="text/javascript">

        $(function(){
            /* 修改样式 */
            $("#gvStudents > tbody > tr:even").not(":first").addClass("even");
            $("#gvStudents > tbody > tr").not(":first")
                .hover(
                    function(){
                        $(this).addClass("hover");
                    },
                    function(){
                        $(this).removeClass("hover");
                });

            /* 全选 */
            $("#gvStudents > tbody > tr:first :checkbox").click(function(){
                if ($(this).attr("checked")){
                    $("#gvStudents :checkbox").attr("checked", "checked");
                    cbChanged();
                } else{
                    $("#gvStudents :checkbox").attr("checked", "");
                    cbChanged();
                }
            });

            /* Checkbox事件 */
            $("#gvStudents :checkbox").not(":first").click(cbChanged);

            $("#btOK").click(function(){
                var r = {};
                r.Items = [];
                
                $("#gvStudents > tbody > tr").not(":first").each(function(){
                    if ($(this).find("input[type='checkbox']").attr("checked")) {
                        var item = {};
                        item.ID = $(this).find("td:nth-child(2)").html();
                        item.Code = $(this).find("td:nth-child(3)").html();
                        item.Name = $(this).find("td:nth-child(4)").html();
                        r.Items.push(item);
                    }
               
                });
                 // alert($.toJSON(r));
                window.returnValue = r;// $.toJSON(r);
                window.close(); 
                
            });

            cbChanged();
        });

        /* 检测Checkbox的选择状态，更改button的disabled属性 */
        function cbChanged(){
            var hasChecked = false;
            var allChecked = true;
            $("#gvStudents :checkbox").not(":first").each(function(index, domEle){
                var curChecked = $(domEle).attr("checked");
                if (!hasChecked && curChecked){
                    hasChecked = true;
                }

                allChecked &= curChecked;
            });

            if (hasChecked){
                $("#btOK").attr("disabled", "");
            } else {
                $("#btOK").attr("disabled", "disabled");
            }

            if (allChecked){
                $("#gvStudents :checkbox").filter(":first").attr("checked", "checked");
            } else {
                $("#gvStudents :checkbox").filter(":first").attr("checked", "");
            }
        }

    </script>

</body>
</html>
